<#assign base=request.contextPath>
<!DOCTYPE html> 
<html>
	<head>
		<title>${title}</title>
		<meta charset="utf-8">
		<#include "common/reference.ftl" />
		<#include "common/am.reference.ftl" />
	</head>
	<body class="${configs["skinName"]}">
		<div class="page-content">
			<div class="row">
			<#if viewMode !="view">
			<#include "common/breadcrumb.ftl">
			</#if>
				<form id="form" role="form" class="form-horizontal" method="post" action="${base}/${form_action}">
					<div class="col-xs-12">
						<div class="widget-box">
							<div class="widget-body">
								<input type="hidden" name="imgId" id="imgId" value="${model.imgId}" required <#if viewMode == "view">disabled</#if>>
								<input type="hidden" name="openId" id="openId" value="${model.openId}" required <#if viewMode == "view">disabled</#if>>
								<#if viewMode == "view">
								<div class="widget-header widget-header-flat">
									<h5 class="lighter">
										${module}
									</h5>
								</div>
								<#else>
								<div class="alert alert-warning">
									<strong>提示!</strong>
									<strong style="color:#dd514c;">出现红框</strong>的表示不能为空
								</div>
								</#if>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right">
										图片
									</label>
									<div class="col-sm-6">
										<#if viewMode !="view">
										<input type="file" id="imageFile" name="file" value="" class="form-control" data-input="imageInput" data-image="imagePreview">
										</#if>
										<input type="hidden" id="imageInput" name="imgUrl" value="${model.imgUrl}" required/>
										<img id="imagePreview" alt="" src="<#if model.imgUrl?exists && model.imgUrl?length gt 0>${model.imgUrl}</#if>" height="60" style="display:<#if model.imgUrl?exists && model.imgUrl?length gt 0>block<#else>none</#if>" />
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right">
										是否启用
									</label>
									<div class="col-sm-6">
										<input class="ace ace-switch ace-switch-7" type="checkbox" name="enabled" <#if model == null || model.enabled>checked="checked"</#if> <#if viewMode == "view">disabled</#if>>
										<span class="lbl"></span>
									</div>
								</div>
								<#if viewMode != "view">
								<div class="clearfix form-actions">
									<div class="col-md-offset-3 col-md-9">
										<button id="btnSubmit" class="btn btn-info" type="button">
											<i class="fa fa-check bigger-110"></i>
											提 交
										</button>
									</div>
								</div>
								</#if>
							</div>
						</div>
					</div>
				</form>
			</div>	
		</div>
		<script type="text/javascript">
		$(function(){
			$('input[type="file"]').ace_file_input(imageParms).on('change',function(){
				var fileId = $(this).attr('id');
				var inputid = $(this).attr('data-input');
				var previewId = $(this).attr('data-image');
				openLoading();
				$.ajaxFileUpload({
		                url: '${base}/upload/image', 
		                type:'POST',
		                data:{module:'carimage',hasRoot:true},          
		                secureuri: false,
		                fileElementId: fileId,                   //文件选择框的id属性
		                dataType: 'json',                       
		                success: function (rst){
		                    if(rst.status == 'OK' && rst.link != ''){
			                    $('#'+previewId).attr('src',rst.link).show();
		                    	$('#'+inputid).val(rst.link);
		                    }
		                    else{
		                    	layer.alert(rst.message);
		                    }
		                },
		                error: function (data, status, e) {
		                    layer.alert('上传图片失败');
		                },
		                complete:function(){
		                	closeLoading();
		                }
		          });
			});
			$('#btnSubmit').click(function(){
				var img = $('#imageInput').val();
				if(!img || img.length < 1){
					layer.alert('请上传图片');
					return;
				}
				$('#form').submit();
			});
			$('#form').validator();
		})
		</script>
	</body>
</html>